from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-29 14:02:37.205589
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 29, Dec, 2022
Time: 14:02:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3197
Nobs: 885.000 HQIC: -51.6203
Log likelihood: 11712.5 FPE: 3.16787e-23
AIC: -51.8064 Det(Omega_mle): 2.86319e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297626 0.049348 6.031 0.000
L1.Burgenland 0.105806 0.033869 3.124 0.002
L1.Kärnten -0.106664 0.018186 -5.865 0.000
L1.Niederösterreich 0.212967 0.071030 2.998 0.003
L1.Oberösterreich 0.083605 0.067191 1.244 0.213
L1.Salzburg 0.250615 0.035963 6.969 0.000
L1.Steiermark 0.029962 0.047230 0.634 0.526
L1.Tirol 0.126937 0.038375 3.308 0.001
L1.Vorarlberg -0.061790 0.033039 -1.870 0.061
L1.Wien 0.065172 0.059911 1.088 0.277
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062499 0.101344 0.617 0.537
L1.Burgenland -0.009180 0.069555 -0.132 0.895
L1.Kärnten 0.049244 0.037347 1.319 0.187
L1.Niederösterreich -0.171597 0.145870 -1.176 0.239
L1.Oberösterreich 0.359768 0.137988 2.607 0.009
L1.Salzburg 0.285816 0.073856 3.870 0.000
L1.Steiermark 0.109316 0.096993 1.127 0.260
L1.Tirol 0.319278 0.078808 4.051 0.000
L1.Vorarlberg 0.025169 0.067850 0.371 0.711
L1.Wien -0.024465 0.123037 -0.199 0.842
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201005 0.025670 7.830 0.000
L1.Burgenland 0.090438 0.017618 5.133 0.000
L1.Kärnten -0.008784 0.009460 -0.929 0.353
L1.Niederösterreich 0.267304 0.036948 7.235 0.000
L1.Oberösterreich 0.111034 0.034952 3.177 0.001
L1.Salzburg 0.053556 0.018707 2.863 0.004
L1.Steiermark 0.015093 0.024568 0.614 0.539
L1.Tirol 0.101511 0.019962 5.085 0.000
L1.Vorarlberg 0.057124 0.017186 3.324 0.001
L1.Wien 0.112688 0.031165 3.616 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104478 0.026300 3.973 0.000
L1.Burgenland 0.047980 0.018050 2.658 0.008
L1.Kärnten -0.016517 0.009692 -1.704 0.088
L1.Niederösterreich 0.197484 0.037855 5.217 0.000
L1.Oberösterreich 0.277425 0.035809 7.747 0.000
L1.Salzburg 0.117882 0.019167 6.150 0.000
L1.Steiermark 0.099657 0.025171 3.959 0.000
L1.Tirol 0.125521 0.020452 6.138 0.000
L1.Vorarlberg 0.070599 0.017608 4.009 0.000
L1.Wien -0.025399 0.031929 -0.795 0.426
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132359 0.047398 2.792 0.005
L1.Burgenland -0.053810 0.032531 -1.654 0.098
L1.Kärnten -0.036428 0.017467 -2.086 0.037
L1.Niederösterreich 0.165889 0.068223 2.432 0.015
L1.Oberösterreich 0.133116 0.064537 2.063 0.039
L1.Salzburg 0.290578 0.034543 8.412 0.000
L1.Steiermark 0.033371 0.045364 0.736 0.462
L1.Tirol 0.159922 0.036858 4.339 0.000
L1.Vorarlberg 0.108658 0.031734 3.424 0.001
L1.Wien 0.067876 0.057544 1.180 0.238
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063882 0.037664 1.696 0.090
L1.Burgenland 0.038452 0.025849 1.488 0.137
L1.Kärnten 0.049914 0.013880 3.596 0.000
L1.Niederösterreich 0.227214 0.054212 4.191 0.000
L1.Oberösterreich 0.266897 0.051282 5.204 0.000
L1.Salzburg 0.060349 0.027448 2.199 0.028
L1.Steiermark -0.007406 0.036047 -0.205 0.837
L1.Tirol 0.157597 0.029288 5.381 0.000
L1.Vorarlberg 0.068361 0.025216 2.711 0.007
L1.Wien 0.075478 0.045726 1.651 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187945 0.045265 4.152 0.000
L1.Burgenland 0.017581 0.031067 0.566 0.571
L1.Kärnten -0.058743 0.016681 -3.522 0.000
L1.Niederösterreich -0.097252 0.065153 -1.493 0.136
L1.Oberösterreich 0.177430 0.061633 2.879 0.004
L1.Salzburg 0.061354 0.032988 1.860 0.063
L1.Steiermark 0.227120 0.043322 5.243 0.000
L1.Tirol 0.483462 0.035200 13.735 0.000
L1.Vorarlberg 0.052407 0.030306 1.729 0.084
L1.Wien -0.049617 0.054955 -0.903 0.367
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155441 0.051126 3.040 0.002
L1.Burgenland 0.000024 0.035089 0.001 0.999
L1.Kärnten 0.066985 0.018841 3.555 0.000
L1.Niederösterreich 0.201244 0.073588 2.735 0.006
L1.Oberösterreich -0.070212 0.069612 -1.009 0.313
L1.Salzburg 0.221105 0.037259 5.934 0.000
L1.Steiermark 0.111445 0.048931 2.278 0.023
L1.Tirol 0.083775 0.039757 2.107 0.035
L1.Vorarlberg 0.125051 0.034229 3.653 0.000
L1.Wien 0.106553 0.062069 1.717 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358505 0.030299 11.832 0.000
L1.Burgenland 0.007739 0.020795 0.372 0.710
L1.Kärnten -0.025384 0.011166 -2.273 0.023
L1.Niederösterreich 0.229414 0.043611 5.260 0.000
L1.Oberösterreich 0.151893 0.041254 3.682 0.000
L1.Salzburg 0.052490 0.022081 2.377 0.017
L1.Steiermark -0.016461 0.028998 -0.568 0.570
L1.Tirol 0.121863 0.023561 5.172 0.000
L1.Vorarlberg 0.072145 0.020285 3.556 0.000
L1.Wien 0.049311 0.036784 1.341 0.180
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039115 0.164048 0.183269 0.170406 0.145921 0.130516 0.067463 0.220390
Kärnten 0.039115 1.000000 0.002684 0.132728 0.027508 0.099824 0.430585 -0.048785 0.101742
Niederösterreich 0.164048 0.002684 1.000000 0.350190 0.173734 0.318344 0.135330 0.194524 0.342107
Oberösterreich 0.183269 0.132728 0.350190 1.000000 0.236553 0.344014 0.183785 0.181880 0.274640
Salzburg 0.170406 0.027508 0.173734 0.236553 1.000000 0.155878 0.141189 0.154647 0.141947
Steiermark 0.145921 0.099824 0.318344 0.344014 0.155878 1.000000 0.164474 0.149626 0.096940
Tirol 0.130516 0.430585 0.135330 0.183785 0.141189 0.164474 1.000000 0.125654 0.165684
Vorarlberg 0.067463 -0.048785 0.194524 0.181880 0.154647 0.149626 0.125654 1.000000 0.021404
Wien 0.220390 0.101742 0.342107 0.274640 0.141947 0.096940 0.165684 0.021404 1.000000